package com.battleship;

import android.media.AudioManager;
import android.os.Bundle;
import android.preference.EditTextPreference;
import android.preference.PreferenceActivity;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnKeyListener;
import android.view.accessibility.AccessibilityEvent;

import com.battleship.preferences.SeekBarPreferences;

public class SettingsActivity extends PreferenceActivity implements
		OnKeyListener {

	SeekBarPreferences shine, volume;

	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		addPreferencesFromResource(R.xml.preferences);

		ca.idi.tecla.lib.ListPreference list_themes = (ca.idi.tecla.lib.ListPreference) findPreference("themeSelected");
		list_themes.setEntries(R.array.themeArray);
		ca.idi.tecla.lib.ListPreference list_fonts = (ca.idi.tecla.lib.ListPreference) findPreference("fontSelected");
		list_fonts.setEntries(R.array.fontArray);

		shine = (SeekBarPreferences) findPreference("shine");
		volume = (SeekBarPreferences) findPreference("volume");
		shine.setWindow(getWindow());
		volume.setWindow(getWindow());
		this.setVolumeControlStream(AudioManager.STREAM_MUSIC);

		this.getListView().setOnKeyListener(this);
		

	}

	@Override
	public boolean onKey(View v, int keyCode, KeyEvent event) {
		if (event.getAction() == KeyEvent.ACTION_UP) {
			switch (keyCode) {
			case KeyEvent.KEYCODE_DPAD_RIGHT:
				if (this.getListView().getSelectedItemPosition() == 3) {				
					volume.padChanges(true);
				} else if (this.getListView().getSelectedItemPosition() == 5) {					
					shine.padChanges(true);
					}
				break;
			case KeyEvent.KEYCODE_DPAD_LEFT:
				if (this.getListView().getSelectedItemPosition() == 3) {					
					volume.padChanges(false);
				} else if (this.getListView().getSelectedItemPosition() == 5) {
					shine.padChanges(false);
				}
				break;
			}
			
			v.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_FOCUSED);
		}

		return false;
	}
	
	

}
